// const crypto = require('crypto')


// -------------Hash--------------
// const hash1 = crypto.createHash('md5');

// hash1.update('Hello, world!');
// hash1.update('Hello, nodejs!');

// console.log(hash1.digest('hex'), 'hash1');


// const hash2 = crypto.createHash('sha1');

// hash2.update('Hello, world!');
// hash2.update('Hello, nodejs!');

// console.log(hash2.digest('hex'), 'hash2');

// -----------------------------------------
// -------Hmac------------------------

// const hmac = crypto.createHmac('md5', 'secret-key');

// hmac.update('Hello, world!');
// hmac.update('Hello, nodejs!');

// console.log(hmac.digest('hex'));

// ---------------------------------------
// -----AES-------------------------------
// function aesEncrypt(data, key) {
//   const cipher = crypto.createCipher('aes192', key);
//   var crypted = cipher.update(data, 'utf8', 'hex');
//   crypted += cipher.final('hex');
//   return crypted;
// }

// function aesDecrypt(encrypted, key) {
//   const decipher = crypto.createDecipher('aes192', key);
//   var decrypted = decipher.update(encrypted, 'hex', 'utf8');
//   decrypted += decipher.final('utf8');
//   return decrypted;
// }

// var data = 'Hello, this is a secret message!';
// var key = 'Password!';
// var encrypted = aesEncrypt(data, key);
// var decrypted = aesDecrypt(encrypted, key);

// console.log('Plain text: ' + data);
// console.log('Encrypted text: ' + encrypted);
// console.log('Decrypted text: ' + decrypted);

// ---------------------------------------------
// ------Diffie-Hellman-------------------------

var crypto = require("crypto");
var assert = require("assert");

var diffieHellman1 = crypto.createDiffieHellman(256);
var prime1 = diffieHellman1.getPrime('base64');
var diffieHellman2 = crypto.createDiffieHellman(prime1, 'base64');
var key1 = diffieHellman1.generateKeys();
var key2 = diffieHellman2.generateKeys('hex');
var secret1 = diffieHellman1.computeSecret(key2, 'hex', 'base64');
var secret2 = diffieHellman2.computeSecret(key1, 'binary', 'base64');

assert.equal(secret1, secret2);
console.log(diffieHellman1.getPrivateKey('hex'))
console.log(diffieHellman2.getPrivateKey('hex'))

console.log(diffieHellman1.getPublicKey('hex'))
console.log(diffieHellman2.getPublicKey('hex'))
console.log(secret1)
console.log(secret2)